/**
 * 
 */
package org.metaverse.restful;

import static org.openrdf.rio.RDFFormat.*;
import static org.restlet.data.MediaType.*;
import org.openrdf.rio.RDFFormat;
import org.restlet.data.MediaType;

/**
 * @author vjache
 *
 */
public class RDFFormatHelper {

	/**
	 * 
	 */
	private RDFFormatHelper() {}
	
	public static RDFFormat toRDFFormat(MediaType mediaType) {
		if(APPLICATION_RDF_TRIG.equals(mediaType))
		{
			return TRIG;
		}
		else if(APPLICATION_RDF_TURTLE.equals(mediaType))
		{
			return TURTLE;
		}
		else if(APPLICATION_RDF_TRIX.equals(mediaType) || APPLICATION_XML.equals(mediaType))
		{
			return TRIX;
		}
		else if(APPLICATION_RDF_XML.equals(mediaType))
		{
			return RDFXML;
		}
		else if(TEXT_RDF_N3.equals(mediaType))
		{
			return N3;
		}
		else if(TEXT_RDF_NTRIPLES.equals(mediaType))
		{
			return NTRIPLES;
		}
		else
			throw new IllegalArgumentException(String.format("Unexpected media type '%s'.", mediaType));
	}
	
	public static MediaType toMediaType(final RDFFormat aRdfFormat)
	{
		if(TURTLE.equals(aRdfFormat))
		{
			return APPLICATION_RDF_TURTLE;
		}
		else if(NTRIPLES.equals(aRdfFormat))
		{
			return TEXT_RDF_NTRIPLES;
		}
		else if(N3.equals(aRdfFormat))
		{
			return TEXT_RDF_N3;
		}
		else if(RDFXML.equals(aRdfFormat))
		{
			return APPLICATION_RDF_XML;
		}
		else if(TRIX.equals(aRdfFormat))
		{
			return APPLICATION_RDF_TRIX;
		}
		else if(TRIG.equals(aRdfFormat))
		{
			return APPLICATION_RDF_TRIG;
		}
		else
			throw new IllegalArgumentException(String.format("Unexpected RDF format '%s'.", aRdfFormat));
	}
}
